<template>
	<view class="">
		<view class="gz">
			{{$t('guize.gzqjq')}}
			< div class='item'>$</ div><br>
			{{$t('guize.key')}}<br>
			{{$t('guize.shli')}}<text>https://www.xbiquwx.la/{{key}}/{{key1}}.html</text>
		</view>
		<cLabel :title="$t('guize.issy')" @hand='handSwitch' :dataText='form.book_state' align='right' mode='switch'
			rightIcon='' />
		<scroll-view scroll-x class="bg-white nav" scroll-with-animation>
			<view class="cu-item" v-for="(item,index) in TabData" :key="index"
				:class="index==TabCur?'text-orange cur':''" @tap="tabSelect" :data-id="index">
				{{item}}
			</view>
		</scroll-view>
		<view v-show="TabCur==0">
			<cLabel :title="$t('guize.symz')" v-model='form.book_name' mode='text' :dataText='form.book_name'
				rightIcon='' />
			<cLabel :title="$t('guize.sywz')" v-model='form.book_url' mode='text' :dataText='form.book_url' rightIcon=''
				:placeholder="$t('yuan.bx')" />
			<cLabel title="图片域名" v-model='form.img_url' mode='text' :dataText='form.img_url' rightIcon=''
				placeholder="设置后将拼接上此域名" />
			<cLabel :title="$t('guize.sswz')" v-model='form.search_url' mode='text' :dataText='form.search_url'
				rightIcon='' :placeholder="$t('yuan.bx')" />
			<cLabel :title="$t('guize.ssgz')" v-model='form.search_http' mode='selectors' :dataText='form.search_http'
				:selectList="selectLists" rightIcon='' :placeholder="$t('yuan.bx')" />
			<cLabel title="header" top="30upx" v-model='form.header' :dataText='form.header' mode='textarea'
				rightIcon='' />
			<cLabel :title="$t('guize.xqwz')" v-model='form.rand_url' mode='text' :dataText='form.rand_url' rightIcon=''
				:placeholder="$t('yuan.bx')" />

			<cLabel :title="$t('guize.nrgz')" v-model='form.body_url' mode='text' :dataText='form.body_url' rightIcon=''
				:placeholder="$t('yuan.bx')" />
			<cLabel :title="$t('guize.szfz')" v-model='form.book_group' mode='text' :dataText='form.book_group'
				rightIcon='' />
		</view>
		<view v-if="TabCur==1">
			<cLabel :title="$t('guize.qjgz')" top="30upx" v-model='form.search_content' :dataText='form.search_content'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.mhjmgz')" top="30upx" v-model='form.search_gz' :dataText='form.search_gz'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.sjidgz')" top="30upx" v-model='form.book_id' :dataText='form.book_id'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.namegz')" top="30upx" v-model='form.search_name' :dataText='form.search_name'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.imggz')" top="30upx" v-model='form.search_img' :dataText='form.search_img'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.zzgz')" top="30upx" v-model='form.search_author' :dataText='form.search_author'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.fzgz')" top="30upx" v-model='form.search_sort' :dataText='form.search_sort'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.jsgz')" top="30upx" v-model='form.search_introduce'
				:dataText='form.search_introduce' mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.zxzjgz')" top="30upx" v-model='form.search_chapter'
				:dataText='form.search_chapter' mode='textarea' rightIcon='' />
		</view>
		<view v-if="TabCur==2">
			
			<cLabel :title="$t('guize.syqjzz')" top="30upx" v-model='form.rand_content' :dataText='form.rand_content'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.shnameid')" top="30upx" v-model='form.rand_id' :dataText='form.rand_id'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.syname')" top="30upx" v-model='form.rand_name' :dataText='form.rand_name'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.syimg')" top="30upx" v-model='form.rand_img' :dataText='form.rand_img'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.syzzgz')" top="30upx" v-model='form.rand_author' :dataText='form.rand_author'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.syfzgz')" top="30upx" v-model='form.rand_sort' :dataText='form.rand_sort'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.syjsgz')" top="30upx" v-model='form.rand_intro' :dataText='form.rand_intro'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.sygxsjtz')" top="30upx" v-model='form.rand_time' :dataText='form.rand_time'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.syzdgz')" top="30upx" v-model='form.rand_state' :dataText='form.rand_state'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.sysjdzgz')" top="30upx" v-model='form.rand_link' :dataText='form.rand_link'
				mode='textarea' rightIcon='' />
		
			
		</view>
		<view v-if="TabCur==3">
			<cLabel :title="$t('guize.syzjdzz')" top="30upx" v-model='form.zhang_url' :dataText='form.zhang_url'
				mode='textarea' rightIcon='' />
			<cLabel title="获取章节地址规则" top="30upx" v-model='form.zhang_link' :dataText='form.zhang_link'
					mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.syzjqjgz')" top="30upx" v-model='form.zhang_content'
				:dataText='form.zhang_content' mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.syzjmh')" top="30upx" v-model='form.zhang_list' :dataText='form.zhang_list'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.syzjid')" top="30upx" v-model='form.zhang_id' :dataText='form.zhang_id'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.syzjmgz')" top="30upx" v-model='form.zhang_name' :dataText='form.zhang_name'
				mode='textarea' rightIcon='' />
			<cLabel :title="$t('guize.syzjdzz')" top="30upx" v-model='form.zhang_link' :dataText='form.zhang_link'
				mode='textarea' rightIcon='' />
		</view>
		<view v-show="TabCur==4">
			<cLabel :title="$t('guize.synrgz')" v-model='form.book_data' mode='textarea' :dataText='form.book_data'
				rightIcon='' />
			<cLabel :title="$t('guize.nrglzd')" v-model='form.book_regular' mode='textarea'
				:dataText='form.book_regular' rightIcon='' :placeholder="$t('guize.dggv')" />
			<cLabel title="分页前置网址" v-model='form.body_furl' mode='textarea' :dataText='form.body_furl'
				rightIcon='' />	
			<cLabel title="自动识别分页规则" v-model='form.book_body' mode='textarea' :dataText='form.book_body'
				rightIcon='' />
			<cLabel :title="$t('guize.fysl')" v-model='form.book_limit' mode='textarea' :dataText='form.book_limit'
				rightIcon='' />
			<cLabel :title="$t('guize.fydz')" v-model='form.book_page' mode='textarea' :dataText='form.book_page'
				rightIcon='' />
		</view>
		<view class="foot">
			<button class="bg-blue" @tap="handSubmit">{{$t('yuan.tj')}}</button>
		</view>
	</view>
</template>
<script>
	var check = require('@/common/checker.js')
	// #ifdef  APP-PLUS
	import _sql from '@/util/sql.js';
	// #endif
	import cLabel from "@/components/cat-label/cat-label.vue"
	export default {
		components: {
			cLabel
		},
		data() {
			return {
				TabCur: 0,
				key: '{{key}}',
				key1: '{{key1}}',
				TabData: [this.$t('guize.listtab1'), this.$t('guize.listtab2'), this.$t('guize.listtab3'),'章节', this.$t(
					'guize.listtab4')],
				selectLists: ['GET', 'POST'],
				form: {
					zhang_url:'',
					body_furl:'',
					book_name: "",
					book_body:"",
					search_http: 'GET',
					search_gz: "",
					book_url: '',
					book_group: '',
					img_url: '',
					search_name: "",
					body_url: "",
					rand_url: "",
					search_url: '',
					search_img: '',
					search_author: '',
					search_sort: '',
					search_introduce: '',
					search_chapter: '',
					rand_name: '',
					rand_img: '',
					rand_sort: '',
					rand_state: '',
					rand_time: '',
					book_regular: '',
					rand_link: '',
					rand_intro: '',
					rand_content: '',
					rand_id: '',
					zhang_id: '',
					zhang_content: '',
					zhang_name: '',
					zhang_link: '',
					search_content: '',
					book_id: '',
					book_data: '',
					book_page: '',
					book_limit: '',
					zhang_list: '',
					rand_author: '',
					header: '',
					book_state: 1
				},
				rules: {},
				id: 0
			}
		},
		onLoad(e) {
			this.id = e.id
			this.sqlselect(this.id)
		},

		methods: {
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
			},
			handSwitch(val) {
				console.log(val)
				this.form.book_state = val;
			},
			handSubmit() {
				this.form.book_state = this.form.book_state ? 1 : 0

				if (!this.form.book_name) {

					uni.showToast({
						title: '书源名字未填写',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.form.book_url) {

					uni.showToast({
						title: '书源网址不正确',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.form.search_url) {
					uni.showToast({
						title: '搜索网址不正确',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (this.id) {
					_sql.Update(this.form, this.id).then(function(res) {
						if (res) {
							uni.navigateBack({
								delta: 1
							});
						}
					});
				} else {
					_sql.insertSQL(this.form).then(function(res) {
						if (res) {
							uni.navigateBack({
								delta: 1
							});
						}
					});
				}
			},
			sqlselect(id) {
				var _this = this;
				if (id) {
					_sql.selectSQL("select * from " + this.dbs + " where id=" + id).then(function(res) {
						_this.form = res[0]
					});
				}
			}

		}
	}
</script>

<style>
	.foot {
		position: fixed;
		bottom: 0;
		width: 100%;
	}

	.gz {
		padding: 25rpx;
		background-color: #e7c000db;
	}
</style>
